Repository navigation
feat(codegen-ts): add service and service-routes generators (ADR-0067 layers 4 and 5) - #641
Merged
Merged
Conversation
… (ADR-0067 part 1) `service` writes one module per metadata package: a function per derived list, get, create, update and delete of each concrete, table-backed, single-key entity. Each write runs in one transaction (a savepoint inside a caller's), loads the row under a row lock, and validates and stamps the body with the declared write rules (ADR-0045). `service-routes` writes the thin Fastify transport over it. Both are ejectable reference generators written through TsWriter. runtime-ts gains the `./service` and `./service/fastify` entries they import, and `meta eject` copies them. The shared generator list gains the `service` layer label in every port. A new api-contract lane runs the shared corpus against the service behind its transport, in both layouts, and a compile gate builds the tier in every dialect.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What Changed
serviceandservice-routes, backed by newcodegen-tswalk and template modules plus ejectable reference copies.servicewrites one module per metadata package. Each concrete, table-backed, single-key entity gets derived list, get, create, update and delete functions, pluscreate<Pkg>Service(deps). Every write runs in one transaction (a savepoint inside a caller'sopts.tx), loads the row under a row lock, and validates and stamps the input with the declared write rules (ADR-0045).service-routeswrites a thin Fastify plugin per package over that service.@metaobjectsdev/runtime-tsgains the./serviceand./service/fastifyentries these import, andmeta ejectcopies them. Write-through, TPH, many-to-many, projections, reports, transitions and declared operations stay on the flat generators.servicelayer label to the shared generator registry manifest, withserviceandservice-routesrows (TypeScript only). The C#, Java, Kotlin and Python registries and their conformance tests accept the new label. Registry, eject and byte-identical reference tests are updated, and the CLI catalog listing and install set know the new generators.business-rules.md,own-your-codegen.md,docs/ports/typescript.md, the codegen skill and its agent-context goldens, ADR-0067, and the CHANGELOG.Validation
Risk Assessment
✅ Low: The change adds two opt-in generators and a runtime module, and the flat generators' output is unchanged. It meets the stated L-TS-4 intent. The earlier fix rounds (async-only sqlite
Db, regenerated goldens and shipped bundle) hold up on re-read, and I found no new defect.Testing
I ran the focused checks for the service generator against real runtimes. The baseline
scripts/ci-local.sh --affected --strict-toolchainshad already passed. The generated service plus transport passed the shared API-contract corpus over HTTP against Testcontainers Postgres. Its emitted code compiled. The runtimeservicemodule passed its own tests, andmeta gen --listshows the newservicelayer. The C# generator-registry and drift tests also passed, including the GUID-narrowed temp-dir test. No source changes were made and no containers I started remain.bun test test/api-contract-service.test.ts test/service-compile.test.tsin integration-tests: 80 pass, 0 fail. The lane generates the service and transport, boots them over HTTP, and the emitted cod…serviceruntime module runs derived writes in one transaction with write rules, and the generator registry lists the new layer (meta gen --listshowsservice, layerservice, requires entit…service.test.ts14 pass. codegen-tsservice-file.test.tsandgenerator-registry.test.ts24 pass, including the async-only sqliteDbalias. Themeta gen --listtranscript is in gen…dotnet testin server/csharp: 11 pass in MetaObjects.Codegen.Tests, covering CodegenDriftTests and GeneratorRegistryConformance.Evidence: meta gen --list output (includes the service layer entry)
Gate and scope
01M815CBVCJFPXJ3GN6MNPWR5R). The "2 runs" above counts its fix rounds. The fixes were:Dbtype is now async-only, so a sync driver such asbetter-sqlite3orbun:sqlitefails at type-check. The docs say the sqlite service needs an async driver such as libsql. A test pins the type.ERR_STORE_NO_INTERACTIVE_TX), the init flag, and the verify advisory.Pipeline
Updates from git push no-mistakes
✅ **Intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
server/typescript/packages/runtime-ts/src/service/index.ts:96- The generated service runs every write throughscope.transaction(fn)with an async callback, andserviceis registered fordialect: sqlite.dbTypeBlock('sqlite')typesDbasBaseSQLiteDatabase<"sync" | "async", ...>, so a sync Drizzle driver type-checks. Per my knowledge of Drizzle (nonode_moduleshere, so I could not confirm in this worktree), abetter-sqlite3database throws "Transaction function cannot return a promise" on an async callback. Abun:sqlitedatabase commits before the awaited statements run. In the first case every create, update and delete fails as a redacted 500. In the second a write can lose its atomicity and row lock silently. The runtime test uses libsql only, and its header comment notes that a sync driver differs. The compile gate builds sqlite output but does not run it. Neitherdocs/features/business-rules.mdnor the generator docs say the sqlite service needs an async driver (libsql/D1). The remedy needs an owner decision: narrow the sqliteDbalias to"async"for the service, document the restriction, or add sync-driver handling ininWriteTransaction.server/typescript/packages/codegen-ts/src/generators/service-routes-file.ts:15- Applied inline: theruntimeImportoption doc onserviceRoutesFilesaid the emitted file imports from@metaobjectsdev/runtime-ts/drizzle-fastify. The emitted transport imports@metaobjectsdev/runtime-ts/service/fastify, so I corrected the comment.src/reference/service-routes.tsalready saysservice/fastify.🔧 Fix applied.
3 issues (1 error, 2 infos) still open:
server/typescript/packages/codegen-ts/src/generators/service-routes-file.ts:15- Applied inline: theruntimeImportoption doc onserviceRoutesFilesaid the emitted file imports from@metaobjectsdev/runtime-ts/drizzle-fastify. The emitted transport imports@metaobjectsdev/runtime-ts/service/fastify, so I corrected the comment.src/reference/service-routes.tsalready saysservice/fastify.server/typescript/packages/codegen-ts/test/service-file.test.ts:67- The fix round (5d9f1bd) narrowed the sqlite serviceDbtoBaseSQLiteDatabase<"async", ...>but added no test. The compile gate (service-compile.test.ts) only proves async output compiles. It cannot catch a regression to"sync" | "async", which would silently bring back the runtime failure review-1 prevented. Add a generation test that emits the service fordialect: sqliteand asserts the emittedservice/index.tsdeclares the async-only alias. The flatqueriesgenerator must keep"sync" | "async"(test/templates/queries-file.test.ts:84). The emitted file is generated public output, so asserting on it is a legitimate contract.agent-context/skills/metaobjects-codegen/SKILL.md:347- The change edits the skill source (heading now 'The seven layers', newservicerow), but the committed outputs generated from it were not regenerated.agent-context-conformance.test.ts(sdk) assembles the stack fromagent-context/and asserts byte equality with each golden, so it fails.agent-context/shipped.test.ts('the shared conformance goldens come out of the tree unchanged') compares the same goldens against the committed shipped tree, so it is stale too. The base-commit skill matched the goldens exactly, so the drift comes from this change. Stale goldens, each still reading 'The six layers, and what picks them' with noservicerow: fixtures/agent-context-conformance/{rust,python,java-react,java-kotlin-react-tanstack,csharp,ts-react-tanstack}/expected/.claude/skills/metaobjects-codegen/SKILL.md. Stale shipped bundle: agent-context-shipped/files/86974256b798cf22.md (the codegen SKILL, still 'six layers') plusagent-context-shipped/manifest.json, whose file hash and name for that entry also change. Fix: runbun scripts/regen-agent-context-conformance.tsin server/typescript/packages/sdk, then rebuild the shipped tree with whatever script ownsagent-context-shipped/(check its README), and commit both.🔧 Fix applied.
📝 2 wording or comment-placement notes left for the author (no fix round spent):
server/typescript/packages/codegen-ts/src/generators/service-routes-file.ts:15- Applied inline: theruntimeImportoption doc onserviceRoutesFilesaid the emitted file imports from@metaobjectsdev/runtime-ts/drizzle-fastify. The emitted transport imports@metaobjectsdev/runtime-ts/service/fastify, so I corrected the comment.src/reference/service-routes.tsalready saysservice/fastify.fixtures/generator-registry-conformance/registry.json:2- Applied inline: the manifest's$commentstill saidlayeris one of model, persistence, api, client, docs, capability. It omitted the newservicelayer that this change adds. I addedserviceto that list. This is wording only, and the file still parses as JSON.🔧 **Test** - 2 issues found → auto-fixed ✅
scripts/ci-local.sh --only ts-slowbefore merge.meta genfrom the fixtureType '"sync"' is not assignable to type '"async"'scripts/ci-local.sh --affected --strict-toolchainsscripts/ci-local.sh --affected --strict-toolchainson HEAD b0d350e0 (ts build+typecheck, ts conformance, ts unit suites, completeness-gate, java-reactor, python, csharp, rust lanes): LOCAL CI PASSED, total wall 5m19sbun server/typescript/packages/sdk/scripts/build-shipped-agent-context.ts --check: agent-context-shipped current (101 files)Live scenario fixture:meta genviabun server/typescript/packages/cli/dist/bin/meta.js genon a one-entity model (acme::shop Note: title maxLength 80, code writeOnce) with entityFile, queriesFile, contractTypes, serviceFile, serviceRoutesFile, barrel; emitted 12 filesLive driverbun drive.ts: generatedcreateShopServicebound to drizzle libsql over a file DB, served by generatedshopServiceRouteson Fastify at 127.0.0.1:4317; real HTTP requests; DB state read back with an independent libsql queryTypecheck:tsc -p tsconfig.json(strict, nodenext) over generated gen/**/*.ts: exit 0Sync-driver probe:tsc -p tsconfig.sync.jsonwith drizzle bun-sqlite passed to createShopService: error TS(Db)Type '"sync"' is not assignable to type '"async"'Focused tests: codegen-tstest/service-file.test.ts(9 pass), runtime-tstest/service.test.ts(14 pass), sdktest/agent-context(138 pass), codegen-tstest/templates/queries-file.test.ts(6 pass)Regression suites:bun testin codegen-ts (3889 pass, 0 fail), cli (2195 ran, 0 fail, 12 skip), sdk (542 pass, 0 fail), runtime-ts (1149 ran, 0 fail, 15 skip)Fixture and driver torn down (scratch dir removed, port 4317 closed); no background processes left; worktree clean🔧 Fix applied.
✅ Re-checked - no issues remain.
bun test test/api-contract-service.test.ts test/service-compile.test.tsin integration-tests: 80 pass, 0 fail. The lane generates the service and transport, boots them over HTTP, and the emitted cod…serviceruntime module runs derived writes in one transaction with write rules, and the generator registry lists the new layer (meta gen --listshowsservice, layerservice, requires entit…service.test.ts14 pass. codegen-tsservice-file.test.tsandgenerator-registry.test.ts24 pass, including the async-only sqliteDbalias. Themeta gen --listtranscript is in gen…dotnet testin server/csharp: 11 pass in MetaObjects.Codegen.Tests, covering CodegenDriftTests and GeneratorRegistryConformance.scripts/ci-local.sh --affected --strict-toolchainsBroad regression came from the configuredscripts/ci-local.sh --affected --strict-toolchains, which passed at this commit and was not re-run.bun test test/service.test.tsin runtime-ts: 14 pass.bun test test/service-file.test.ts test/generator-registry.test.tsin codegen-ts: 24 pass.bun test test/api-contract-service.test.ts test/service-compile.test.tsin integration-tests, which boots Testcontainers Postgres: 80 pass.bun bin/meta.ts gen --listin the cli package: the output includes aserviceentry withlayer: service.dotnet test --filter "CodegenDriftTests|GeneratorRegistryConformance"in server/csharp: 11 pass in MetaObjects.Codegen.Tests.✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.